
package com.jf.cloud.platform.controller;

import com.alibaba.fastjson.JSON;
import com.jf.cloud.common.response.ResponseEnum;
import com.jf.cloud.common.response.ServerResponseEntity;
import com.jf.cloud.platform.constant.WebConfigType;
import com.jf.cloud.platform.service.SysConfigService;
import com.jf.cloud.platform.vo.WebConfigVO;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * 网站配置信息表
 *
 * @author zz
 */
@RestController("allWebConfigController")
@RequestMapping("/ua/web_config")
@Tag(name = "网站配置信息表")
public class WebConfigController {

    @Autowired
    private SysConfigService sysConfigService;

    @GetMapping("/get_activity")
    @Operation(summary = "获取当前激活的网站配置" , description = "获取当前激活的网站配置")
    @Parameter(name = "webConfigType", description = "配置类型" )
    public ServerResponseEntity<WebConfigVO> getActivityWebConfig(@RequestParam("webConfigType") String webConfigType) {
        WebConfigType paramKey = WebConfigType.instance(webConfigType);
        if (Objects.isNull(paramKey)) {
            return ServerResponseEntity.fail(ResponseEnum.HTTP_MESSAGE_NOT_READABLE);
        }
        String paramValue = sysConfigService.getValue(paramKey.value());
        WebConfigVO webConfigVO = JSON.parseObject(paramValue, WebConfigVO.class);
        webConfigVO.setParamKey(webConfigType);
        return ServerResponseEntity.success(webConfigVO);
    }
}
